﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using Hotnet.Biz.NSBizCommon;
using Hotnet.Entity;
using Hotnet.Entity.Enum;
using Hotnet.Entity.Search;
using Hotnet.Web.Utility;

namespace Hotnet.Web.Controllers.Admin
{
	public class AdminTagController : AdminBaseController
	{
		//
		// GET: /AdminTag/

		private BizTag bizTag;
		private const int pageSize = 15;

		public AdminTagController(BizTag bizTag)
		{
			this.bizTag = bizTag;
		}


		public ActionResult Index(int? pageNo,SearchTagCondition searchObj)
		{
			int totalCount=0;
			Tag[] list = bizTag.List(pageNo ?? 0, pageSize, out totalCount, searchObj);
			ViewData["PaginateHelper"] = PaginateHelper.ConstructPaginate(totalCount, pageNo ?? 0, pageSize, "/AdminTag/Index/", searchObj);
			return View(list);
		}

		//
		// POST: /AdminTag/Create

		[AcceptVerbs(HttpVerbs.Post)]
		public ActionResult Create(Tag model)
		{
			model.ClickCount = 100;
			model.RefCount = 0;
			model.AddTime = DateTime.Now;
			bizTag.Insert(model);
			return RedirectToAction("Index");
		}

		//
		// POST: /AdminTag/Edit/5

		[AcceptVerbs(HttpVerbs.Post)]
		public ActionResult Edit(Tag model)
		{
			bizTag.Update(
				tag => tag.TagID == model.TagID,
				tag => new Tag { TagName = model.TagName, TargetType = model.TargetType }
			);

			return RedirectToAction("Index");
		}

		[AcceptVerbs(HttpVerbs.Post)]
		public ActionResult Delete(int? id)
		{
			bizTag.Delete(id ?? 0);
			return RedirectToAction("Index");
		}



	}


}
